home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / dflat2.zip / APPLICAT.C next >
Text File  |  1991-04-18  |  8KB  |  329 lines

  1. /* ------------- applicat.c ------------- */
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include "dflat.h"
  7.  
  8. static WINDOW mnu = NULLWND;
  9. extern DBOX TabStops;
  10.  
  11. static void ChooseWindow(WINDOW, int);
  12. static void SelectColors(void);
  13. static void CloseAll(WINDOW);
  14.  
  15. int ApplicationProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  16. {
  17.     int rtn;
  18.     static int tabstop;
  19.  
  20.     switch (msg)    {
  21.         case CREATE_WINDOW:
  22.             LoadConfig();
  23.             SelectColors();
  24.             rtn = BaseWndProc(APPLICATION, wnd, msg, p1, p2);
  25.             if (wnd->extension != NULL)    {
  26.                 mnu = CreateWindow(MENUBAR,
  27.                                     NULL,
  28.                                     GetLeft(wnd)+1,
  29.                                     GetTop(wnd)+1,
  30.                                     1,
  31.                                     WindowWidth(wnd)-2,
  32.                                     NULL,
  33.                                     wnd,
  34.                                     NULL,
  35.                                     0);
  36.                 SendMessage(mnu, BUILDMENU, (PARAM) wnd->extension, 0);
  37.                 SelectColors();
  38.                 AddAttribute(wnd, HASMENUBAR);
  39.                 SendMessage(mnu, SETFOCUS, TRUE, TRUE);
  40.                 if (cfg.InsertMode)
  41.                     SetCommandToggle(ID_INSERT);
  42.                 if (cfg.WordWrap)
  43.                     SetCommandToggle(ID_WRAP);
  44.             }
  45.             PostMessage(wnd, CAPTURE_CLOCK, 0, 0);
  46.             return rtn;
  47.         case SIZE:
  48.             BaseWndProc(APPLICATION, wnd, msg, p1, p2);
  49.             SendMessage(mnu, HIDE_WINDOW, 0, 0);
  50.             SendMessage(mnu, SIZE, GetRight(wnd)-1, GetTop(wnd)+1);
  51.             SendMessage(mnu, BUILDMENU, (PARAM) wnd->extension, 0);
  52.             SendMessage(mnu, SHOW_WINDOW, 0, 0);
  53.             return TRUE;
  54.         case KEYBOARD:
  55.             if (WindowSizing || WindowMoving)
  56.                 break;
  57.             PostMessage(mnu, msg, p1, p2);
  58.             return TRUE;
  59.         case SETFOCUS:
  60.             return FALSE;
  61.         case PAINT:
  62.             if (isVisible(wnd))
  63.                 ClearWindow(wnd, (RECT *)p1, APPLCHAR);
  64.             return TRUE;
  65.         case COMMAND:
  66.             switch ((int)p1)    {
  67.                 case ID_EXIT:
  68.                 case ID_SYSCLOSE:
  69.                     PostMessage(wnd, CLOSE_WINDOW, 0, 0);
  70.                     break;
  71.                 case ID_COLOR:
  72.                     if (!cfg.mono)
  73.                         break;
  74.                     cfg.mono = FALSE;
  75.                     SelectColors();
  76.                     SendMessage(mnu, BUILDMENU, (PARAM) wnd->extension, 0);
  77.                     SendMessage(wnd, SHOW_WINDOW, 0, 0);
  78.                     break;
  79.                 case ID_MONO:
  80.                     if (cfg.mono)
  81.                         break;
  82.                     cfg.mono = TRUE;
  83.                     SelectColors();
  84.                     SendMessage(mnu, BUILDMENU, (PARAM) wnd->extension, 0);
  85.                     SendMessage(wnd, SHOW_WINDOW, 0, 0);
  86.                     break;
  87.                 case ID_TABS:
  88.                     tabstop = cfg.Tabs;
  89.                     switch (tabstop)    {
  90.                         case 2:
  91.                             PushRadioButton(&TabStops, ID_TAB2);
  92.                             break;
  93.                         case 4:
  94.                             PushRadioButton(&TabStops, ID_TAB4);
  95.                             break;
  96.                         case 6:
  97.                             PushRadioButton(&TabStops, ID_TAB6);
  98.                             break;
  99.                         case 8:
  100.                             PushRadioButton(&TabStops, ID_TAB8);
  101.                             break;
  102.                         default:
  103.                             break;
  104.                     }
  105.                     if (DialogBox(wnd, &TabStops, NULL))
  106.                         cfg.Tabs = tabstop;
  107.                     break;
  108.                 case ID_TAB2:
  109.                     tabstop = 2;
  110.                     break;
  111.                 case ID_TAB4:
  112.                     tabstop = 4;
  113.                     break;
  114.                 case ID_TAB6:
  115.                     tabstop = 6;
  116.                     break;
  117.                 case ID_TAB8:
  118.                     tabstop = 8;
  119.                     break;
  120.                 case ID_SAVEOPTIONS:
  121.                     SaveConfig();
  122.                     break;
  123.                 case ID_WINDOW:
  124.                     ChooseWindow(wnd, (int)p2);
  125.                     break;
  126.                 case ID_CLOSEALL:
  127.                     CloseAll(wnd);
  128.                     break;
  129.                 case ID_SYSRESTORE:
  130.                 case ID_SYSMOVE:
  131.                 case ID_SYSSIZE:
  132.                 case ID_SYSMINIMIZE:
  133.                 case ID_SYSMAXIMIZE:
  134.                     return BaseWndProc(APPLICATION, wnd, msg, p1, p2);
  135.                 default:
  136.                     if (inFocus != mnu)
  137.                         PostMessage(inFocus, msg, p1, p2);
  138.                     break;
  139.             }
  140.             return TRUE;
  141.         case LEFT_BUTTON:    {
  142.             WINDOW wnd1 = wnd;
  143.             int mx, my;
  144.             if (WindowSizing || WindowMoving)
  145.                 return FALSE;
  146.             if (SendMessage(wnd, INSIDE_WINDOW, p1, p2))    {
  147.                 if (inFocus && inFocus != mnu)
  148.                     if (SendMessage(inFocus, INSIDE_WINDOW, p1, p2))
  149.                         wnd1 = inFocus;
  150.                 mx = (int) p1 - GetLeft(wnd1);
  151.                 my = (int) p2 - GetTop(wnd1);
  152.                 if (HitControlBox(wnd1, mx, my))    {
  153.                     BuildSystemMenu(wnd1);
  154.                     return TRUE;
  155.                 }
  156.             }
  157.             break;
  158.         }
  159.         case CLOCKTICK:    {
  160.             WINDOW wnd1 = Focus.LastWindow;
  161.             int x = GetLeft(wnd)+WindowWidth(wnd)-9;
  162.             while (wnd1 != NULLWND && wnd1 != wnd)    {
  163.                 if (SendMessage(wnd1, INSIDE_WINDOW, x, GetTop(wnd)))
  164.                     return TRUE;
  165.                 if (SendMessage(wnd1, INSIDE_WINDOW, x+5, GetTop(wnd)))
  166.                     return TRUE;
  167.                 wnd1 = PrevWindow(wnd1);
  168.             }
  169.             foreground = cfg.clr.TitleFG;
  170.             background = cfg.clr.TitleBG;
  171.             wputs(wnd, (char *)p1, WindowWidth(wnd)-9, 0);
  172.             return TRUE;
  173.         }
  174.         case CLOSE_WINDOW:
  175.             SendMessage(NULLWND, RELEASE_CLOCK, 0, 0);
  176.             PostMessage(NULLWND, STOP, 0, 0);
  177.             break;
  178.         default:
  179.             break;
  180.     }
  181.     return BaseWndProc(APPLICATION, wnd, msg, p1, p2);
  182. }
  183.  
  184. void PrepEditMenu(void *wnd, struct Menu *mnu)
  185. {
  186.     struct PopDown *pd = mnu->Selections;
  187.     while (pd->SelectionTitle != NULL)    {
  188.         if (*pd->SelectionTitle != LINE)    {
  189.             switch (pd->ActionId)    {
  190.                 case ID_CUT:
  191.                 case ID_COPY:
  192.                 case ID_CLEAR:
  193.                 case ID_DELETETEXT:
  194.                     if (GetClass(inFocus) == EDITBOX &&
  195.                         isMultiLine(inFocus) &&
  196.                             BlockMarked(inFocus))
  197.                         pd->Attrib &= ~INACTIVE;
  198.                     else
  199.                         pd->Attrib |= INACTIVE;
  200.                     break;
  201.                 case ID_PARAGRAPH:
  202.                     if (GetClass(inFocus) == EDITBOX &&
  203.                             isMultiLine(inFocus))
  204.                         pd->Attrib &= ~INACTIVE;
  205.                     else
  206.                         pd->Attrib |= INACTIVE;
  207.                     break;
  208.                 case ID_PASTE:
  209.                     if (GetClass(inFocus) == EDITBOX &&
  210.                             isMultiLine(inFocus) &&
  211.                                 !TestAttribute(inFocus, READONLY) &&
  212.                                     Clipboard != NULL)
  213.                         pd->Attrib &= ~INACTIVE;
  214.                     else
  215.                         pd->Attrib |= INACTIVE;
  216.                     break;
  217.                 case ID_UNDO:
  218.                     if (GetClass(inFocus) == EDITBOX &&
  219.                             inFocus->DeletedText != NULL)
  220.                         pd->Attrib &= ~INACTIVE;
  221.                     else
  222.                         pd->Attrib |= INACTIVE;
  223.                     break;
  224.                 default:
  225.                     break;
  226.             }
  227.         }
  228.         pd++;
  229.     }
  230. }
  231.  
  232. void PrepOptionsMenu(void *wnd, struct Menu *mnu)
  233. {
  234.     struct PopDown *pd = FindCmd(ID_TABS);
  235.     sprintf(pd->SelectionTitle+7, "%d", cfg.Tabs);
  236. }
  237.  
  238. static char *Menus[9] = {
  239.     "~1.                      ",
  240.     "~2.                      ",
  241.     "~3.                      ",
  242.     "~4.                      ",
  243.     "~5.                      ",
  244.     "~6.                      ",
  245.     "~7.                      ",
  246.     "~8.                      ",
  247.     "~9.                      "
  248. };
  249.  
  250. void PrepWindowMenu(void *wnd, struct Menu *mnu)
  251. {
  252.     struct PopDown *pd = mnu->Selections;
  253.     struct PopDown *ca = mnu->Selections + 12;
  254.     int MenuNo = 0;
  255.     WINDOW wnd1 = Built.FirstWindow;
  256.     mnu->Selection = 0;
  257.     while (wnd1 != NULLWND && MenuNo < 9)    {
  258.         if (GetClass(wnd1) != MENUBAR && GetParent(wnd1) == wnd)    {
  259.             strncpy(Menus[MenuNo]+4, GetTitle(wnd1), 20);
  260.             pd->SelectionTitle = Menus[MenuNo];
  261.             if (wnd1 == inFocus)    {
  262.                 pd->Attrib |= CHECKED;
  263.                 mnu->Selection = MenuNo;
  264.             }
  265.             else
  266.                 pd->Attrib &= ~CHECKED;
  267.             pd++;
  268.             MenuNo++;
  269.         }
  270.         wnd1 = NextWindowBuilt(wnd1);
  271.     }
  272.     if (MenuNo)    {
  273.         *pd++ = *ca++;
  274.         *pd++ = *ca;
  275.     }
  276.     pd->SelectionTitle = NULL;
  277. }
  278.  
  279. static void ChooseWindow(WINDOW wnd, int WindowNo)
  280. {
  281.     WINDOW wnd1 = GetFirstChild(wnd);
  282.     while (wnd1 != NULLWND)    {
  283.         if (GetClass(wnd1) != MENUBAR)
  284.             if (WindowNo-- == 0)
  285.                 break;
  286.         wnd1 = GetNextChild(wnd);
  287.     }
  288.     if (inFocus->condition == ISMAXIMIZED)
  289.         SendMessage(inFocus, RESTORE, 0, 0);
  290.     SendMessage(wnd1, SETFOCUS, TRUE, 0);
  291.     if (wnd1->condition == ISMINIMIZED)
  292.         SendMessage(wnd1, RESTORE, 0, 0);
  293. }
  294.  
  295. static void SelectColors(void)
  296. {
  297.     if (ismono() || video_mode == 2)    {
  298.         cfg.mono = TRUE;
  299.         DeactivateCommand(ID_COLOR);
  300.     }
  301.     if (cfg.mono)    {
  302.         cfg.clr = bw;
  303.         SetCommandToggle(ID_MONO);
  304.         ClearCommandToggle(ID_COLOR);
  305.     }
  306.     else    {
  307.         cfg.clr = color;
  308.         SetCommandToggle(ID_COLOR);
  309.         ClearCommandToggle(ID_MONO);
  310.     }
  311. }
  312.  
  313. static void CloseAll(WINDOW wnd)
  314. {
  315.     int closing = TRUE;
  316.     while (closing)    {
  317.         WINDOW wnd1 = GetLastChild(wnd);
  318.         closing = FALSE;
  319.         while (GetClass(wnd1) != MENUBAR)    {
  320.             if (wnd1 == inFocus)    {
  321.                 SendMessage(wnd1, CLOSE_WINDOW, 0, 0);
  322.                 closing = TRUE;
  323.                 break;
  324.             }
  325.             wnd1 = GetPrevChild(wnd);
  326.         }
  327.     }
  328. }
  329.